<template>
	
 	<div class="layui-layout layui-layout-admin" >
 	  <div class="adminnav1">	
        <Pagetop></Pagetop>
      </div>
      <div class="adminnav2">	
       	<Secondnav urlname="shopjf"></Secondnav>
      </div>
      
      <!-- 主体内容 -->
      <div class="layui-body kedou-admin" id="LAY_app_body app">
	    <div class="layadmin-tabsbody-item layui-show">
	    	<div class="pagelist">
	    		<div class="layui-card-body">
		      		<fieldset class="layui-elem-field layui-field-title">
					  <legend>积分商品分组</legend>
					</fieldset>
		      	</div>
	    		<div class="pagetop">
	    			<Search :seadate="searchArr"></Search>			    	
		        </div>
		        <div class="layui-card-body">
		        	<div class="buttop">
					    <button type="button" class="layui-btn  layui-btn-normal" @click="addData">添加商品分组</button>
					</div>
			        <Tables :fdate="pdate" :result="res" height="430" :totalCount="totalRows" :pageNumber="curindex" :fbtn="btn"></Tables>      			     
		        </div>		      
	        </div>
	    </div>
	  </div>  
	     
	</div>
</template>
<script>	
	import Pagetop from '../../common/pagetop.vue'
	import Secondnav from '../../common/secondnav.vue'
	import Tables from '../../common/tables.vue'
	import Search from '../../common/search.vue'
	export default {
	  name: 'jfgrouplist',
	  components: {Pagetop,Secondnav,Tables,Search},	  
	  data () {
	    return {
	        pdate:[], //表头  	
	    	res:"", //内容
	    	totalRows:"",//总数量
	    	curindex:1, //页数
	    	btn:[],//按钮
	    	searchArr:[],//搜索
	    	isShow:false, 
	    	seapram:''   	
	    }
	  },
	  mounted(){ 	
	  	this.getdate();
     	this.getsearch();
	  },
	  methods: {	 	  
		getdate:function(){ 
    	var _this=this;    	    	
    	var url="/huanxinsong/group/listJson"
    	if(_this.seapram){
    		var dates={
	    		pageSize:pageSize,
	    		pageNumber:this.curindex
	    	}
    		var res=_this.seapram;
    		for(var i=0;i<res.length;i++){
    			dates[res[i].key]=res[i].val;
    		}
    		
    	}else{
	    	var dates={
	    		pageSize:pageSize,
	    		pageNumber:this.curindex
	    	}
       }  		    	
      	ajaxRequest(url,'GET','json',dates,function(ret,err){
      		//alert(url+"//"+JSON.stringify(ret))
	  		var arr=[];  		
		  	arr[0]=[ 
		       {field: 'id', title: '分组ID',}
		      ,{field: 'name', title: '分组名称',}		     
		      ,{field: 'right',title: '操作', width:'120', fixed:'right',templet:function(d){ 
		         var str='<a class="layui-btn layui-btn-xs layui-btn-normal" lay-event="edit">编辑</a>';
		         return str;
		      }}
		    ];		   
		  	_this.pdate=arr;		  	
		  	_this.res=ret.content;
		  	_this.totalRows=1.1;
		  	_this.curindex=ret.content.pageNumber;		  	
	    })	
    },     
     getsearch:function(){
    	var arr=[
//  		{field: 'name', title: '门店名称',type: 'input'}     		 		   	   
    	];
    	this.searchArr=arr;
   	
    },
    page:function(index,obj){
    	//alert(JSON,stringify(obj))
    	this.curindex=index;
    	this.getdate();
    	
    }, 
    sousuo:function(pram){
    	//alert(JSON.stringify(pram))
    	this.seapram=pram;
    	this.res='';
    	this.totalRows='';
    	this.curindex=1;
    	this.getdate();
    },
    addData:function(){
		var _this = this;
		layer.open({
	        type:1
	        ,title: '创建信息'	        
	        ,content:'<div style="padding:50px;"><input  class="layui-input" name="a" value="" type="text" placeholder="请输入分组名称"></div>'
	        ,btn:['确定']
	        ,yes:function (index, layero) {
	        	var val=$('input[name="a"]').val();
	        	var shopId=localStorage.getItem("shopId");
	        	if(val){
	        		var url = "/huanxinsong/group/save";  
	        		var date={
	        			shopId:shopId,
						name:val,
					}
	        		//alert(JSON.stringify(date))
					ajaxRequest(url,'GET','json',date,function(ret,err){
						layer.msg("操作成功")
						setTimeout(function(){
							_this.getdate();
							parent.layer.close(index);
						},2000)
					})
	        		
	        	}
	        	else{
	        		layer.msg("请输入名称")
	        	}
            } 
        })    
	},	
	editInfo:function(data){
		var _this = this;
		layer.open({
	        type:1
	        ,title: '编辑信息'	        
	        ,content:'<div style="padding:50px;"><input  class="layui-input" name="a" value="'+data.name+'" type="text" ></div>'
	        ,btn:['确定']
	        ,yes:function (index, layero) {
	        	//alert(JSON.stringify(layero))	        	
	        	var val=$('input[name="a"]').val();		        	
	        	if(val){
	        		var url = "/huanxinsong/group/update";  
	        		var date={
						id:data.id,					
						name:val,
						shopId:data.shopId,
					}
					ajaxRequest(url,'GET','json',date,function(ret,err){
						layer.msg("操作成功")
						setTimeout(function(){
							_this.getdate();
							parent.layer.close(index);
						},2000)
					})
	        		
	        	}
	        	else{
	        		layer.msg("请输入名称")
	        	}
            } 
        })    
	},
	
	
	
	screens:function(){
		return screen();
	},	
  },
  updated:function(){
  	this.isShow = true;
	layui.use('form', function(){
	  var form = layui.form;
	  form.render();	 
	});
  },
}
</script>
<style scoped>
/**/
</style>
